package com.mid;

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

/**
 * Created by Lxk on 2020/1/29.
 */
public class Solution173 {

    private Set<Integer> nodeSet = new TreeSet<>();

    private Iterator<Integer> iterator;

    private void midOrderVisit(TreeNode node) {
        if (node == null) {
            return;
        }
        midOrderVisit(node.left);
        nodeSet.add(node.val);
        midOrderVisit(node.right);
    }

    public Solution173(TreeNode root) {
        midOrderVisit(root);
        iterator = nodeSet.iterator();
    }

    /**
     * @return the next smallest number
     */
    public int next() {
        return iterator.next();
    }

    /**
     * @return whether we have a next smallest number
     */
    public boolean hasNext() {
        return iterator.hasNext();
    }

}
